package com.example.rbacmanage.service.app.impl;

import com.example.rbacmanage.annotation.PermissionRange;
import com.example.rbacmanage.entity.app.ShopInfo;
import com.example.rbacmanage.mapper.app.ShopInfoMapper;
import com.example.rbacmanage.service.app.ShopInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ShopInfoServiceImpl implements ShopInfoService {
    @Autowired
    private ShopInfoMapper shopInfoMapper;
    @Override
    public void save(ShopInfo shopInfo) {
        shopInfo.setCreateTime(new Date());
        shopInfoMapper.insert(shopInfo);
    }

    @Override
    public void remove(Long[] ids) {
        for (Long id : ids) {
            shopInfoMapper.del(id);
        }
    }

    @Override
    public void update(ShopInfo shopInfo) {
        shopInfoMapper.update(shopInfo);
    }

    @PermissionRange(shopAlias = "s")
    @Override
    public List<ShopInfo> getAll(ShopInfo shopInfo) {
        return shopInfoMapper.list(shopInfo);
    }

    @PermissionRange(shopAlias = "s")
    @Override
    public PageInfo<ShopInfo> getPage(ShopInfo shopInfo) {
        PageHelper.startPage(shopInfo.getPage(),shopInfo.getLimit());
        return new PageInfo<>(getAll(shopInfo));
    }

    @Override
    public ShopInfo getById(Long id) {
        return shopInfoMapper.queryOneById(id);
    }

    @Override
    public Integer getCount(ShopInfo shopInfo) {
        return shopInfoMapper.count(shopInfo);
    }
}
